package vlms.controller;

import java.io.IOException;
import java.rmi.RemoteException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import vlms.bean.Person;
import vlms.service.VLMSServiceProxy;
import wrapper.MovieIssue;

/**
 * Servlet implementation class Confirm
 */
public class Confirm extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Confirm() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
String destination = null;
		
		String message = null,result = "false"; 
		HttpSession session = request.getSession();
		Person oPerson = (Person) session.getAttribute("Person");
		String sPersonId = String.valueOf(oPerson.getPersonid());
		
		try
		 {
			 VLMSServiceProxy proxy = new VLMSServiceProxy();
			 MovieIssue[] aMovieIssue = proxy.checkoutMovie(sPersonId);
			 request.setAttribute("message", "Order Placed Successfully");
			 request.setAttribute("MovieIssue", aMovieIssue);
			 destination = "/bill.jsp";
		 }
		 catch(RemoteException re)
		 {
			 destination = "/ViewCart";
			 request.setAttribute("message", re.getMessage());
			 re.printStackTrace();
		 }
		
		RequestDispatcher rd = this.getServletContext().getRequestDispatcher(destination);
		rd.forward(request, response);
		
	}

}
